package net.Crystal.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


import net.Crystal.database.ConnectionRe;
import net.Crystal.database.SQLquery;
import net.Crystal.dao.pojo.*;

public class StartDao {
	private Connection conn;
	private ResultSet rs;
	private PreparedStatement ps;
	private ConnectionRe connections=new ConnectionRe();
	
	private static boolean DEBUG = true;

    public List<TUsers> start(){
    	List<TUsers> re=new ArrayList<TUsers>();
		TUsers users;
		conn=connections.getNetSQL();
		try {
			ps=conn.prepareStatement(SQLquery.users);
			rs=ps.executeQuery();
			while(rs.next()) {
				users=new TUsers();
				users.setUname(rs.getString("username"));
				if(DEBUG) System.out.println("username"+rs.getString("username"));
				re.add(users);
			}
		}catch(SQLException e){
			e.printStackTrace();
		}finally {
			try {
				conn.close();
			}catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return re;
    }
    
	public String test(){
    	String re="";
    	conn=connections.getNetSQL();
		try {
			ps=conn.prepareStatement(SQLquery.userinfo);
			rs=ps.executeQuery();
			if (rs.next()) {
				re+=(rs.getString(1))+"\n";
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return re;
    }
    public int testprint(){
    	conn=connections.getNetSQL();
		try {
			ps=conn.prepareStatement(SQLquery.userinfo);
			rs=ps.executeQuery();
			if (rs.next()) {
				System.out.println(rs.getString(1));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return 0;
    }
}
